package src.mcpichess.pieces;

import java.util.ArrayList;

import src.mcpichess.control.Main;


public class Queen extends Piece{
	
	public Queen(Main m){
		byte[][][] s = {
				{{1,1,1},{1,0,1},{1,1,1}},
				{{0,0,0},{0,1,0},{0,0,0}},
				{{0,0,0},{0,1,0},{0,0,0}},		//Queen
				{{0,1,0},{1,1,1},{0,1,0}},
				{{1,1,1},{1,1,1},{1,1,1}},
			};
		structure = s;
		main = m;
	}
	
	@Override
	public ArrayList<int[]> getMoves(int x, int z, int player) {
		ArrayList<int[]> rList = new ArrayList<int[]>();
		
		int testX = x;
		int testZ = z;
		
		while (testX < 7){
			testX++;
			if (main.getPieceAt(Main.pair(testX, testZ)) != main.empty){	//tests to see if a piece is in that space
				if (main.getPlayerAt(Main.pair(testX, testZ)) != player){	//if the piece in the space belongs to the other
					rList.add(Main.pair(testX, testZ));
				}
				testX = 8;
			}
			if (testX <= 7){
				rList.add(Main.pair(testX, testZ));
			}
				
		}
		
		testX = x;
		testZ = z;
		
		while (testX > 0){
			testX--;
			if (main.getPieceAt(Main.pair(testX, testZ)) != main.empty){	//tests to see if a piece is in that space
				if (main.getPlayerAt(Main.pair(testX, testZ)) != player){	//if the piece in the space belongs to the other
					rList.add(Main.pair(testX, testZ));
				}
				testX = -1;
			}
			if (testX >= 0){
				rList.add(Main.pair(testX, testZ));
			}
				
		}
		
		testX = x;
		testZ = z;
		
		while (testZ < 7){
			testZ++;
			if (main.getPieceAt(Main.pair(testX, testZ)) != main.empty){	//tests to see if a piece is in that space
				if (main.getPlayerAt(Main.pair(testX, testZ)) != player){	//if the piece in the space belongs to the other
					rList.add(Main.pair(testX, testZ));
				}
				testZ = 8;
			}
			if (testZ <= 7){
				rList.add(Main.pair(testX, testZ));
			}
				
		}
		
		testX = x;
		testZ = z;
		
		while (testZ > 0){
			testZ--;
			if (main.getPieceAt(Main.pair(testX, testZ)) != main.empty){	//tests to see if a piece is in that space
				if (main.getPlayerAt(Main.pair(testX, testZ)) != player){	//if the piece in the space belongs to the other
					rList.add(Main.pair(testX, testZ));
				}
				testZ = -1;
			}
			if (testZ >= 0){
				rList.add(Main.pair(testX, testZ));
			}
				
		}
		
		testX = x;
		testZ = z;
		
		while (testX < 7 && testZ < 7){
			testX++;
			testZ++;
			if (main.getPieceAt(Main.pair(testX, testZ)) != main.empty){	//tests to see if a piece is in that space
				if (main.getPlayerAt(Main.pair(testX, testZ)) != player){	//if the piece in the space belongs to the other
					rList.add(Main.pair(testX, testZ));
				}
				testX = 8;
			}
			if (testX <= 7 && testZ <= 7){
				rList.add(Main.pair(testX, testZ));
			}
				
		}
		
		testX = x;
		testZ = z;
		
		while (testX > 0 && testZ < 7){
			testX--;
			testZ++;
			if (main.getPieceAt(Main.pair(testX, testZ)) != main.empty){	//tests to see if a piece is in that space
				if (main.getPlayerAt(Main.pair(testX, testZ)) != player){	//if the piece in the space belongs to the other
					rList.add(Main.pair(testX, testZ));
				}
				testX = -1;
			}
			if (testX >= 0 && testZ <= 7){
				rList.add(Main.pair(testX, testZ));
			}
				
		}
		
		testX = x;
		testZ = z;
		
		while (testX < 7 && testZ > 0){
			testX++;
			testZ--;
			if (main.getPieceAt(Main.pair(testX, testZ)) != main.empty){	//tests to see if a piece is in that space
				if (main.getPlayerAt(Main.pair(testX, testZ)) != player){	//if the piece in the space belongs to the other
					rList.add(Main.pair(testX, testZ));
				}
				testX = 8;
			}
			if (testX <= 7 && testZ >= 0){
				rList.add(Main.pair(testX, testZ));
			}
				
		}
		
		testX = x;
		testZ = z;
		
		while (testX > 0 && testZ > 0){
			testX--;
			testZ--;
			if (main.getPieceAt(Main.pair(testX, testZ)) != main.empty){	//tests to see if a piece is in that space
				if (main.getPlayerAt(Main.pair(testX, testZ)) != player){	//if the piece in the space belongs to the other
					rList.add(Main.pair(testX, testZ));
				}
				testZ = -1;
			}
			if (testX >=0 && testZ >= 0){
				rList.add(Main.pair(testX, testZ));
			}
				
		}
		
		return rList;
	}

	@Override
	public int getBlockAt(int x, int y, int z) {
		return structure[y][z][x];
	}
	
	@Override
	public int getNum() {
		return 5;
	}
	
}
